package com.itheima.Config;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

public class MybatisConfig {
    @Bean
    public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource) {
        SqlSessionFactoryBean sf = new SqlSessionFactoryBean();
        //设置数据源
        sf.setDataSource(dataSource);
        //设置别名，指向pojo类
        sf.setTypeAliasesPackage("com.itheima.pojo");
        return sf;
    }

    //下面是动态代理，放在容器中，指向mapper
    @Bean
    public MapperScannerConfigurer mapperScannerConfigurer() {
        MapperScannerConfigurer mc = new MapperScannerConfigurer();
        //别名，指向mapper
        mc.setBasePackage("com.itheima.mapper");
        return mc;
    }

}
